//
//  XMStatusForwardCell.swift
//  XMWeibo-Swift
//
//  Created by 育鑫 王 on 15/11/2.
//  Copyright © 2015年 育鑫 王. All rights reserved.
//

import UIKit

// 转发微博cell
class XMStatusForwardCell : XMStatusCell {
    
    // 覆盖父类的模型属性
    // 添加 override 关键字,实现属性监视器,先调用父类的属性监视器,在调用子类的属性监视器
    override var status: XMStatus? {
        didSet {
//            print("status:\(status)")
            // 设置转发微博label的内容
            let name = status?.retweeted_status?.user?.name ?? "名称为空"
            let text = status?.retweeted_status?.text ?? "内容为空"
            forwardLabel.text = "@\(name):\(text)"
        }
    }
    
    override func prepareUI() {
        super.prepareUI()
        // 添加子控件
        contentView.insertSubview(bkgButton, belowSubview: pictureView)
        contentView.addSubview(forwardLabel)
        
        // 添加约束
        // 背景
        // 左上角约束
        bkgButton.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: contentLabel, size: nil, offset: CGPoint(x: -8, y: 8))
        bkgButton.ff_AlignVertical(type: ff_AlignType.TopRight, referView: bottomView, size: nil)
    
        forwardLabel.ff_AlignInner(type: ff_AlignType.TopLeft, referView: bkgButton, size: nil, offset: CGPoint.init(x: 8, y: 0))
    
        // 宽度约束
        contentView.addConstraint(NSLayoutConstraint(item: forwardLabel, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: UIScreen.mainScreen().bounds.width - 2 * 8))
        
        // 配图的约束
        let cons = pictureView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: forwardLabel, size:CGSize(width: 0, height: 0), offset: CGPoint(x: 0, y: 8))
        
        pictureViewWidthCons = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Width)
        pictureViewHeightCons = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Height)
        
    }
    
    
    // MARK: - 懒加载
    /// 灰色的背景
    private lazy var bkgButton: UIButton = {
        let button = UIButton()
        
        //设置背景
        button.backgroundColor = UIColor(white: 0.9, alpha: 1)
        
        return button
    }()
    
    /// 转发文本
    private lazy var forwardLabel : UILabel = {
        let label = UILabel()
        label.textColor = UIColor.darkGrayColor()
        label.numberOfLines = 0
//        label.text = "阿红的空间按时付款拉货收到了罚款哈斯洛克的发挥区位；理解的发放给；哦我的回复就爱我给他钱嘎嘣"
        
        return label
    }()
}